<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>龙信凯数据管理平台</title>

    <!-- CSS -->
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:400,100,300,500">
    <link rel="stylesheet" href="/resources/assets/css/bootstrap.min.css">
    <link rel="stylesheet" href="/resources/assets/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/resources/assets/css/form-elements.css">
    <link rel="stylesheet" href="/resources/assets/css/style.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Favicon and touch icons -->
    <link rel="shortcut icon" href="/resources/assets/ico/favicon.png">
    <link rel="apple-touch-icon-precomposed" sizes="144x144"
          href="/resources/assets/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114"
          href="/resources/assets/ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72"
          href="/resources/assets/ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="/resources/assets/ico/apple-touch-icon-57-precomposed.png">

</head>

<body>

<!-- Top content -->
<div class="top-content">

    <div class="inner-bg">
        <div class="container">
            <div class="row">
                <div class="col-sm-8 col-sm-offset-2 text">
                    <h1><strong>Admin</strong> Login Form</h1>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6 col-sm-offset-3 form-box">
                    <div class="form-top">
                        <div class="form-top-left">
                            <h3>贵州龙信凯科技有限公司</h3>
                            <p>龙信凯数据管理平台</p>
                            <p class="login-message"></p>
                        </div>
                        <div class="form-top-right">
                            <i class="fa fa-lock"></i>
                        </div>
                    </div>
                    <div class="form-bottom">
                        <form id="loginForm">
                            <div class="form-group">
                                <label class="sr-only">Username</label>
                                <input type="text" name="userName" placeholder="账户"
                                       class="userName form-username form-control">
                            </div>
                            <div class="form-group">
                                <label class="sr-only">Password</label>
                                <input type="password" name="userPassword" placeholder="密码"
                                       class="userPassword form-password form-control">
                            </div>
                            <button type="button" class="btn" id="loginBtn">登 录</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>


<!-- Javascript -->
<script src="/resources/assets/js/jquery-3.3.1.min.js"></script>
<script src="/resources/assets/js/bootstrap.min.js"></script>
<script src="/resources/assets/js/jquery.backstretch.min.js"></script>
<script>

    jQuery(document).ready(function () {
        $.backstretch("/resources/assets/img/backgrounds/1.jpg");
    });

    // 登录
    $("#loginBtn").on("click", function () {
        if ($(".userName").val() != null && $(".userName").val().length != 0) {
            if ($(".userPassword").val() != null && $(".userPassword").val().length != 0) {
                $.ajax({
                    type: "POST",
                    url: "/login",
                    data: $("#loginForm").serialize(),
                    dataType: "json",
                    success: function(data) {
                        if (data.message == "success") {
                            window.location.href="/";
                        } else {
                            alert(data.message);
                            $(".login-message").html(data.message).css({"color": "red"});
                        }
                    },
                    error: function () {
                        $(".login-message").html("请求失败，服务器错误").css({"color": "red"});
                    }
                });
            }else {
                $(".login-message").html("请输入管理员密码").css({"color": "red"});
            }
        } else {
            $(".login-message").html("请输入管理员账户").css({"color": "red"});
        }
    });

</script>

</body>

</html>